<template>
  <div>
    <div class="gl_searchBox gl_mb_15">
      <el-row :gutter="20">
        <el-col :span="4">
          <p>申报名称</p>
          <el-input v-model="qo.Filter" placeholder="请输入申报名称" size="mini" clearable @change="getPageList()" />
        </el-col>
        <el-col :span="6">
          <p>考试时间</p>
          <el-date-picker
            v-model="chooseTime"
            size="mini"
            type="daterange"
            style="width:100%"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="handleTimeChange"
          />
        </el-col>
        <el-col :span="4">
          <p>考官</p>
          <el-input v-model="qo.OfficialName" placeholder="请输入考官姓名" size="mini" clearable @change="getPageList()" />
        </el-col>
        <el-col :span="6" class="search_btn">
          <!-- 查询按钮 -->
          <el-button type="primary" size="mini" @click="getPageList()">筛选</el-button>
          <!-- 重置按钮 -->
          <el-button type="warning" size="mini" @click="reset()">重置</el-button>
        </el-col>
      </el-row>
    </div>
    <el-table v-loading="loading" class="gl_table_noBorder" :data="tableData" size="mini">
      <el-table-column label="序号" type="index" />
      <el-table-column label="申报名称" prop="request.name" :min-width="120" />
      <el-table-column label="考试时间" min-width="165">
        <template slot-scope="scope">
          <span v-if="scope.row.request.startTime">
            {{ scope.row.request.startTime | FormatDate('yyyy-MM-dd') }}
          </span>至
          <span v-if="scope.row.request.endTime">
            {{ scope.row.request.endTime | FormatDate('yyyy-MM-dd') }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="考试地点" prop="request.address" :min-width="150" />
      <el-table-column label="考官" :min-width="120">
        <template slot-scope="{row}">
          <span v-for="(item, index) in row.request.officials" :key="item.id">
            {{ item.name }} {{ row.request.officials.length - 1 === index ? '': '/' }}
          </span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="180">
        <template slot-scope="{ row }">
          <el-button size="mini" type="text" @click="toDetail(row.id)">详情</el-button>
          <el-button size="mini" type="text" @click="toaddstudent(row.id)">参加考试</el-button>
          <el-button size="mini" type="text" @click="toViewScore(row.id, row.request.name)">查看成绩</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-row class="gl_mt_15" style="text-align: right;">
      <el-pagination
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="qo.MaxResultCount"
        :current-page="qo.Page"
        @size-change="changePageSize"
        @current-change="changePage"
      />
    </el-row>
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex';
import {
  Api_GET_ClubDuanExamParticipableListQO // 获取可参与考试
} from '@/lib/form/hall/swaggerForm';
import {
  api_GET_ClubDuanExamParticipableList // 获取可参与考试
} from '@/extend/api/hallswaggerApi/app';
export default {
  data () {
    return {
      qo: new Api_GET_ClubDuanExamParticipableListQO(),
      tableData: [],
      loading: false,
      total: 0,
      chooseTime: []
    };
  },
  computed: {
    ...mapState({
      dict: state => state.dict.dict,
      cache: state => state.dict.cache
    })
  },
  created() {
    this.getDict();
    this.getPageList();
  },
  methods: {
    // 若没有字典信息，外部可直接调用方法获取字典数据
    ...mapActions({ getDict: 'dict/getDict' }),
    getPageList(page) {
      this.qo.Page = page || 1;
      this.qo.SkipCount = (this.qo.Page - 1) * this.qo.MaxResultCount;
      this.qo.IncludeOfficials = true;
      this.qo.IncludeRequest = true;
      this.qo.IncludeParticipatingUnits = true;
      this.qo.Sorting = 'creationTime DESC';
      this.loading = true;
      api_GET_ClubDuanExamParticipableList(this.qo).then(res => {
        this.loading = false;
        this.tableData = res.items;
        this.total = res.totalCount;
      }, error => {
        this.loading = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    reset() {
      this.qo = new Api_GET_ClubDuanExamParticipableListQO();
      this.qo.chooseTime = [];
      this.getPageList();
    },
    // 激活
    clickActivation(row) {
      if (row.id) {
        this.loading = true;
        api_GET_ClubDuanExamParticipableList(row.id).then(res => {
          this.loading = false;
          this.$message({ type: 'success', message: '激活成功' });
          this.getPageList(this.qo.Page);
        }, error => {
          this.loading = false;
          const _msg = error.error.message || error.message;
          this.$message({ type: 'error', message: _msg });
        });
      }
    },
    // 跳转可参加考试学员列表
    toaddstudent(id) {
      this.$router.push({ name: 'Addstudentlist', query: { id: id, type: 'join' }});
    },
    // 跳转查看成绩列表
    toViewScore(id, name) {
      this.$router.push({ name: 'ViewScore', query: { type: 'join', duanExamId: id, name: name }});
    },
    // 跳转到详情页
    toDetail(id) {
      this.$router.push({ name: 'ExamDetail', query: { examId: id, type: 'join' }});
    },
    handleTimeChange(time) {
      this.qo.StartTime = time ? time[0] + ' 00:00:00' : null;
      this.qo.EndTime = time ? time[1] + ' 23:59:59' : null;
      this.getPageList();
    },
    // 分页
    changePage(page) {
      this.getPageList(page);
    },
    changePageSize(pagesize) {
      this.qo.MaxResultCount = pagesize;
      this.getPageList();
    }
  }
};
</script>

<style lang="scss" scoped>

</style>
